<template>
	<el-form  :model="patientform" :rules="rules" ref="patientform"  label-width="80px">
	
		<el-form-item label="病人号">
			<el-input v-model="patientform.patientId"></el-input>
		</el-form-item>
		<el-form-item label="姓名" prop="name">
			<el-input v-model="patientform.name"></el-input>
		</el-form-item>
		<el-form-item label="性别" prop="sex">
			<el-input v-model="patientform.sex"></el-input>
		</el-form-item>
		<el-form-item label="年龄" prop="age">
			<el-input v-model="patientform.age"></el-input>
		</el-form-item>
		<el-form-item label="身份证" prop="idcard">
			<el-input v-model="patientform.idcard"></el-input>
		</el-form-item>
		<el-form-item label="出生日期" prop="birthday">
			<el-date-picker
						      v-model="patientform.birthday"
						      type="date"
							  value-format="yyyy-MM-dd"
						      placeholder="选择日期">
						    </el-date-picker>
		</el-form-item>
		<el-form-item label="主治医生" prop="contact">
			<el-input v-model="patientform.contact"></el-input>
		</el-form-item>
		<el-form-item label="手机号" prop="telphone">
			<el-input v-model="patientform.telphone"></el-input>
		</el-form-item>
		<el-form-item label="住址" prop="address">
			<el-input v-model="patientform.address"></el-input>
		</el-form-item>
		<el-form-item label="病房号" prop="room">
			<el-input v-model="patientform.room"></el-input>
		</el-form-item>
		<el-form-item label="所属楼房" prop="building">
			<el-input v-model="patientform.building"></el-input>
		</el-form-item>
		<el-form-item label="入住时间" prop="indate">
			<el-date-picker
						      v-model="patientform.indate"
						      type="date"
							  value-format="yyyy-MM-dd"
						      placeholder="选择日期">
						    </el-date-picker>
		</el-form-item>
		<el-form-item label="搬出时间">
			<el-date-picker
						      v-model="patientform.outdate"
						      type="date"
							  value-format="yyyy-MM-dd"
						      placeholder="选择日期">
						    </el-date-picker>
		</el-form-item>
		<el-form-item label="备注">
			<el-input v-model="patientform.remark"></el-input>
		</el-form-item>
		<el-form-item label="护工">
			<el-input v-model="patientform.nursingId"></el-input>
		</el-form-item>
		
		<el-button type="primary" @click="doPatientAdd('patientform')">提交</el-button>
	</el-form>
</template>

<script>
	
	export default{
		name:'PatientAdd',
		props:[
			'dialogVisible'
		],
		data(){
			return {
				patientform:{
					patientId:'',
					name:'',
					sex:'',
					age:'',
					idcard:'',
					birthday:'',
					contact:'',
					telphone:'',
					address:'',
					room:'',
					building:'',
					indate:'',
					outdate:'',
					remark:'',
					nursingId:''
																		},
		    rules: {
		              name: [
		                { required: true, message: '请输入客户名称', trigger: 'blur' },
		                { min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
		              ],
		              sex: [
		                { required: true, message: '请选择性别', trigger: 'blur' }
		              ],
					  age: [
					    { required: true, message: '请输入年龄', trigger: 'blur' }
					  ],
					  idcard: [
					    { required: true, message: '请输入身份证号', trigger: 'blur' },
						{ min: 18, max: 18, message: '长度为18个字符', trigger: 'blur' }
					  ],
					  birthday: [
					         { required: true, message: '请选择出生日期', trigger: 'change' }
					     ],
					  cantact: [
					    { required: true, message: '请选择主治医生', trigger: 'blur' }
					  ],
					  telphone: [
					    { required: true, message: '请输入电话号', trigger: 'blur' },
						{ min: 11, max: 11, message: '长度在 11 个字符', trigger: 'blur' }
					  ],
					  room: [
					    { required: true, message: '请选择房间号', trigger: 'blur' }
					  ],
					  building: [
					    { required: true, message: '请选择所属楼', trigger: 'blur' }
					  ],
					  indate: [
					              { required: true, message: '请选择入住日期', trigger: 'change' }
					            ],
					
		            }
			}
		},
		methods:{
			
			doPatientAdd(patientform){
				console.log(this.patientform);
				this.$refs[patientform].validate((valid) => {
				  if (valid) {
				    alert('submit!');
					
					
					this.getRequest("/patient/insert",this.patientform).then(resp=>{
					if(resp){
						
						this.$emit("update:dialogVisible",false);
						this.$emit("add")
						
					}else{
						Message.error({message:'保存失败'});
					}
				})
				
				
				  } else {
				    alert('error submit!!');
				    return false;
				  }
				});
				
			}
		}
	}
</script>

<style>
</style>
